using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using BLToolkit.Data;
using BLToolkit.DataAccess;


namespace Brainsoft.Core.BusinessLogic
{    
    public class Roles
    {
        #region Private Properties
        protected int _roleId;
        protected string _nombreRol = String.Empty;
        protected string _descripcion = String.Empty;
        //protected int _ApplicationID = 0;
        #endregion

        #region Public Properties

        public int RoleId
        {
            get { return _roleId; }
            set { _roleId = value; }
        }

        public string NombreRol
        {
            get { return _nombreRol; }
            set { _nombreRol = value; }
        }

        public string Descripcion
        {
            get { return _descripcion; }
            set { _descripcion = value; }
        }

        //public int ApplicationID
        //{
        //    get { return _ApplicationID; }
        //    set { _ApplicationID = value; }
        //}
        #endregion

        #region Generic Methods

        #region Insert, Update, Delete

        public void Insert(Roles obj)
        {
            Query.Insert(obj);
        }

        public void Update(Roles obj)
        {
            Query.Update(obj);
        }

        public void Delete(Roles obj)
        {
            Query.Delete(obj);
        }
        
        public void Delete(int id)
        {
            Query.DeleteByKey(id);
        }

        #endregion

        #region Select
                
        public List<Roles> SelectAll()
        {
            return Query.SelectAll();
        }
        
        public Roles SelectByKey(object[] parameters)
        {
            return Query.SelectByKey(parameters);
        }

        #endregion

        #endregion               

        #region Custom Methods
        public List<Roles> GetRolesByUserId(decimal UserId)
        {
            using (db = new DbManager("Connection String"))
            {
                List<Roles> l = new List<Roles>();
                l = db.SetSpCommand("Roles_SelectByUserId"
                        , db.Parameter("@UserId", UserId))
                        .ExecuteList<Roles>();
                db.Close();
                return l;
            }            
        }
        public Roles GetRolesByRoleName(string rolName)
        {
            using (db = new DbManager("Connection String"))
            {                
                return db.SetSpCommand("Roles_SelectByRoleName"
                        , db.Parameter("@NombreRol", rolName))
                        .ExecuteObject<Roles>();                
            }
        }
        #endregion 

        #region Protected Members

        protected DbManager db;

        private SprocQuery<Roles> _query;
        protected virtual SprocQuery<Roles> Query
        {
            get
            {
                if (null == _query)
                    db = new DbManager("Connection String");                
                    _query = new SprocQuery<Roles>(db);
                return _query;
            }
        }

        #endregion
    }   
}
